import { FinancialItem, FinancialType } from "./models";
import req from "/@/api/req";

export const Api = {
  invoicePage: "mall-ums/api/v1/financial/invoices/page",
  invoice: "mall-ums/api/v1/financial/invoices",
  invoiceReview: "mall-ums/api/v1/financial/invoices/review",
  invoiceNullify: "mall-ums/api/v1/financial/invoices/nullify",

  checkBillPage: "mall-ums/api/v1/financial/online-reconciliations/page",
  checkBill: "mall-ums/api/v1/financial/online-reconciliations",
  checkBillReview: "mall-ums/api/v1/financial/online-reconciliations/review",
  checkBillNullify: "mall-ums/api/v1/financial/online-reconciliations/nullify",
  checkBillDetail: "mall-ums/api/v1/financial/online-reconciliations/detail",
  checkBillPush: "mall-ums/api/v1/financial/online-reconciliations/push",
  checkBillReset: "mall-ums/api/v1/financial/online-reconciliations/reset",
  checkBillGenerate: "mall-ums/api/v1/financial/online-reconciliations/generate-settlement",

  paymentPage: "mall-ums/api/v1/financial/payment-receipts/page",
  payment: "mall-ums/api/v1/financial/payment-receipts",
  paymentReview: "mall-ums/api/v1/financial/payment-receipts/review",
  paymentNullify: "mall-ums/api/v1/financial/payment-receipts/nullify",
  paymentDetail: "mall-ums/api/v1/financial/payment-receipts/{id}/form",

  settlementPage: "mall-ums/api/v1/financial/settlements/page",
  settlement: "mall-ums/api/v1/financial/settlements",
  settlementReview: "mall-ums/api/v1/financial/settlements/review",
  settlementNullify: "mall-ums/api/v1/financial/settlements/nullify",
  settlementDetail: "mall-ums/api/v1/financial/settlements/detail",

  docList: "mall-ums/api/v1/financial/online-reconciliations/documents",
};

export function changeFinancialStatus(changeApiKey: keyof typeof Api, id: number) {
  return req.put(
    {
      url: Api[changeApiKey],
      data: { id },
    },
    { useGlobalLoading: true }
  );
}

export function getFinancialDetail(data: any, financialType: FinancialType) {
  let url = Api[financialType + "Detail"] as string;
  if (url.includes("{id}")) {
    url = url.replace("{id}", data.id);
  }
  return req.commonGet<FinancialItem>(url, data, {
    useGlobalLoading: true,
  });
}
